#include <vector>
#include <iostream>

using namespace std;

class Solution 
{
public:
    void moveZeroes(vector<int>& nums) 
    {
        if(nums.empty())
        {
            return;
        }
        int fast = 0, slow = 0;
        while(fast < nums.size() && slow < nums.size())
        {
            while (slow < nums.size() && nums[slow] != 0)
            {
                slow++;
            }
            fast = slow + 1;
            while(fast < nums.size() && nums[fast] == 0)
            {
                fast++;
            }
            if(fast >= nums.size())
            {
                break;
            }
            swap(nums[slow], nums[fast]);
            slow ++;
        }
    }
};

// 辅助函数：打印数组
void printArray(const vector<int>& nums) 
{
    cout << "[";
    for(int i = 0; i < nums.size(); i++) 
    {
        cout << nums[i];
        if(i < nums.size() - 1) cout << ",";
    }
    cout << "]" << endl;
}

int main() 
{
    Solution solution;
    
    // 测试案例1: [0,1,0,3,12]
    cout << "测试案例1:" << endl;
    vector<int> nums1 = {0, 1, 0, 3, 12};
    cout << "输入: ";
    printArray(nums1);
    solution.moveZeroes(nums1);
    cout << "输出: ";
    printArray(nums1);
    cout << "期望: [1,3,12,0,0]" << endl << endl;
    
    // 测试案例2: [0]
    cout << "测试案例2:" << endl;
    vector<int> nums2 = {0};
    cout << "输入: ";
    printArray(nums2);
    solution.moveZeroes(nums2);
    cout << "输出: ";
    printArray(nums2);
    cout << "期望: [0]" << endl << endl;
    
    // 测试案例3: 无零数组
    cout << "测试案例3 (无零):" << endl;
    vector<int> nums3 = {1, 2, 3, 4, 5};
    cout << "输入: ";
    printArray(nums3);
    solution.moveZeroes(nums3);
    cout << "输出: ";
    printArray(nums3);
    cout << "期望: [1,2,3,4,5]" << endl << endl;
    
    // 测试案例4: 全零数组
    cout << "测试案例4 (全零):" << endl;
    vector<int> nums4 = {0, 0, 0, 0};
    cout << "输入: ";
    printArray(nums4);
    solution.moveZeroes(nums4);
    cout << "输出: ";
    printArray(nums4);
    cout << "期望: [0,0,0,0]" << endl << endl;
    
    // 测试案例5: 零在开头
    cout << "测试案例5 (零在开头):" << endl;
    vector<int> nums5 = {0, 0, 1, 2, 3};
    cout << "输入: ";
    printArray(nums5);
    solution.moveZeroes(nums5);
    cout << "输出: ";
    printArray(nums5);
    cout << "期望: [1,2,3,0,0]" << endl << endl;
    
    // 测试案例6: 零在末尾
    cout << "测试案例6 (零在末尾):" << endl;
    vector<int> nums6 = {1, 2, 3, 0, 0};
    cout << "输入: ";
    printArray(nums6);
    solution.moveZeroes(nums6);
    cout << "输出: ";
    printArray(nums6);
    cout << "期望: [1,2,3,0,0]" << endl << endl;
    
    // 测试案例7: 交替零和非零
    cout << "测试案例7 (交替):" << endl;
    vector<int> nums7 = {0, 1, 0, 2, 0, 3};
    cout << "输入: ";
    printArray(nums7);
    solution.moveZeroes(nums7);
    cout << "输出: ";
    printArray(nums7);
    cout << "期望: [1,2,3,0,0,0]" << endl << endl;
    
    // 测试案例8: 单个非零元素
    cout << "测试案例8 (单个非零):" << endl;
    vector<int> nums8 = {1};
    cout << "输入: ";
    printArray(nums8);
    solution.moveZeroes(nums8);
    cout << "输出: ";
    printArray(nums8);
    cout << "期望: [1]" << endl << endl;
    
    // 测试案例9: 负数和零
    cout << "测试案例9 (负数):" << endl;
    vector<int> nums9 = {-1, 0, -2, 0, 3};
    cout << "输入: ";
    printArray(nums9);
    solution.moveZeroes(nums9);
    cout << "输出: ";
    printArray(nums9);
    cout << "期望: [-1,-2,3,0,0]" << endl << endl;
    
    return 0;
}